package com.windoent.yugioh.adapter.brvah;

import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.windoent.yugioh.R;
import com.windoent.yugioh.bean.RuiShiLunListData;
import com.windoent.yugioh.utils.BaseMethod;
import com.windoent.yugioh.utils.SimpleUtils;
import com.windoent.yugioh.widget.RoundImageView;

/**
 * author : robert
 * date   : 2021/5/6 15:26
 * desc   :
 */
public class RuiShiLunRankListAdapter extends BaseQuickAdapter<RuiShiLunListData.DataBean.CurrentUserBean, BaseViewHolder> {

    public RuiShiLunRankListAdapter() {
        super(R.layout.item_ruishilun_rank_list, null);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, RuiShiLunListData.DataBean.CurrentUserBean item) {
        helper.setText(R.id.tv_numbers, BaseMethod.notNullDefaultValueNull(item.getRank() + ""))
                .setText(R.id.tv_name, BaseMethod.notNullDefaultValueNull(item.getNickname()))
                .setText(R.id.tv_rank, BaseMethod.notNullDefaultValueNull(item.getScore() + ""))
                .setText(R.id.tv_points, BaseMethod.notNullDefaultValueNull(item.getTiebreaker()));

        RoundImageView iv_avatar = helper.getView(R.id.iv_avatar);
        SimpleUtils.loadImageForView(getContext(), iv_avatar, item.getAvatar(), R.drawable.img_official_avatar_android);

        int layoutPosition = helper.getLayoutPosition();
        LinearLayout mLlParent = helper.getView(R.id.ll_rank);
        if (layoutPosition == getData().size()) {
            mLlParent.setBackgroundResource(layoutPosition % 2 == 1 ? R.drawable.drawable_adapter_baoming_shenhe_gray_corner_bg : R.drawable.drawable_adapter_baoming_shenhe_normal_color_bg);
        } else {
            mLlParent.setBackgroundResource(layoutPosition % 2 == 1 ? R.drawable.drawable_adapter_baoming_shenhe_gray_bg : R.drawable.drawable_adapter_baoming_shenhe_normal_bg);
        }
    }
}